package com.myastro.main.jni;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLSurfaceView;


public class NativeRenderer implements GLSurfaceView.Renderer
{
	public NativeRenderer(String lesson) {
		nativeInit(lesson);
	}

	
	@Override
	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
		nativeInitGL();
	}
	
	@Override
	public void onSurfaceChanged(GL10 gl, int width, int height) {
        //gl.glViewport(0, 0, w, h);
        nativeResize(width, height);
	}
	
	@Override
	public void onDrawFrame(GL10 arg0) {
		nativeRender();
	}
	
	public void doPauseRenderer() {
		nativePause();
	}
	
	public void doDestroy() {
		nativeDone();
	}
	
	public void doHandleKeyPress(int keycode, boolean pressed)
	{
		nativeHandleKeyPress(keycode, pressed);
	}
	
	public void doTouchEvent(int pointer_id, int actionCode, float x, float y)
	{
		nativeTouchEvent(pointer_id, actionCode, x, y);
	}
	
	private static native void nativeInit(String lesson);
    private static native void nativeInitGL();
    private static native void nativeResize(int w, int h);
    private static native void nativeRender();
    private static native void nativeDone();
    private static native void nativePause();
    private static native void nativeHandleKeyPress(int keycode, boolean pressed);
    private static native void nativeTouchEvent(int pointer_id, int actionCode, float x, float y);
}



